﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DiamondDesktop.Presenters;

namespace DiamondDesktop.Model
{
    using DiamondDesktop.type;

    [Serializable]
    public class Task
    {
        private const int FULL_PERCENT = 100;

        private long taskId;
        private string title="";
        /* The content of the task */
        private string content="";
        private DateTime actionStartTime;
        private DateTime actionEndTime;

        /* The priority of the task */
        private int priority = 1;

        private int completedDegree = 0;
        private DateTime completedTime;
        private DateTime taskStartTime;
        private DateTime taskEndTime;

        /* The type of the task */
        private TaskType taskType = TaskType.OTHER;

        /* Is the task must be completed */
        private bool must = false;


        private RemindInfo info = null;



        public string Title
        {
            get
            {
                return title;
            }
        }

        public string Content
        {
            get
            {
                return content;
            }
        }


        public string Priority
        {
            get
            {
                return "" + priority;
            }
        }

        public string TaskStartTime
        {
            get
            {
                return taskStartTime.ToString();
            }
        }
        public string TaskEndTime
        {
            get
            {
                if (new DateTime(taskId).Date == DateTime.Now.Date && isExpired())
                    return "过期未完成";
                return taskEndTime.ToString();
            }
        }

        public string ActionStartTime
        {
            get
            {
                return actionStartTime.ToString();
            }
        }
        public string ActionEndTime
        {
            get
            {
                return actionEndTime.ToString();
            }
        }
        public string Compeletion
        {
            get
            {
                if (completedDegree == 100)
                    return "完成";
                return "未完成";
            }
        }

        public string Must
        {
            get
            {
                if (must)
                    return "必须";
                return " ";
            }
        }

        public string Id
        {
            get
            {
                DateTime d = new DateTime(taskId);
                return d.ToString();
            }
        }

        public Task()
        {
            taskId = DateTime.Now.Ticks;
        }

        public void regenerateId()
        {
            generateId(DateTime.Now);
        }

        private void generateId(DateTime d)
        {
            DateTime old = new DateTime(taskId);
            taskId = d.Date.Add(old.TimeOfDay).Ticks;
        }

        public long getTaskId()
        {
            return taskId;
        }

        public string getTitle()
        {
            return title;
        }

        public void setTitle(string t)
        {
            title = t;
        }

        public string getContent()
        {
            return content;
        }

        public void setContent(string s)
        {
            content = s;
        }

        public DateTime getActionStartTime()
        {
            return actionStartTime;
        }

        public void setActionStartTime(DateTime time)
        {
            actionStartTime = time;
        }

        public DateTime getActionEndTime()
        {
            return actionEndTime;
        }

        public void setActionEndTime(DateTime time)
        {
            actionEndTime = time;
        }

        public bool isMust()
        {
            return must;
        }

        public void setMust(bool flag)
        {
            must = flag;
        }

        public Status getStatus()
        {
            if (completedDegree == 100)
                return Status.FINISHED;
            else
                return Status.UNFINISHED;
        }

        public bool isCompleted()
        {
            return completedDegree == FULL_PERCENT;
        }

        public void setCompleted()
        {
            setPercent(FULL_PERCENT);
            completedTime = DateTime.Now;
        }

        public int getPercent()
        {
            return completedDegree;
        }

        public void setPercent(int percent)
        {
            completedDegree = percent;
        }


        public DateTime getCompletedTime()
        {
            return completedTime;
        }

        public void setCompletedTime(DateTime time)
        {
            completedTime = time;
        }

        public DateTime getTaskStartTime()
        {
            return taskStartTime;
        }

        public void setTaskStartTime(DateTime time)
        {
            taskStartTime = time;
            generateId(time);
        }

        public DateTime getTaskEndTime()
        {
            return taskEndTime;
        }

        public void setTaskEndTime(DateTime time)
        {
            taskEndTime = time;
        }

        public int getPriority()
        {
            return priority;
        }

        public void setPriority(int p)
        {
            priority = p;
        }

        public TaskType getType()
        {
            return taskType;
        }

        public void setType(TaskType type)
        {
            taskType = type;
        }

        public RemindInfo getRemindInfo()
        {
            return info;
        }

        public void setRemindInfo(RemindInfo info)
        {
            this.info = info;
        }

        public bool isExpired()
        {
            return taskEndTime < DateTime.Now;
        }






    }
}
